<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>药店进销货管理系统</title>
    <link rel="shortcut icon" href="favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="styles/common.css"/>
    <link rel="stylesheet" href="styles/index.css"/>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">
    <style>
        .body {
            min-width: 1366px;
        }

        .app-main {
            height: calc(100% - 64px);
        }

        .app-main .divTmp {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
<div class="app" id="app">
    <div class="app-wrapper openSidebar clearfix">
        <!-- sidebar -->
        <div class="sidebar-container">
            <div class="logo" style="font-family: STHupo;font-size: 20px">
                药店进销存<br/>管理系统<br/>
                <div style="font-family: STCaiyun">MedTrack</div>
            </div>

            <el-scrollbar wrap-class="scrollbar-wrapper">
                <el-menu
                        :default-active="defAct"
                        :unique-opened="false"
                        :collapse-transition="false"
                        background-color="#ffffff"
                        text-color="#000"
                        active-text-color="#000">
                    <div v-for="item in menuList" :key="item.id">
                        <el-submenu :index="item.id" v-if="item.children && item.children.length>0">
                            <template slot="title">
                                <i class="iconfont" :class="item.icon"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item
                                    v-for="sub in item.children"
                                    :index="sub.id"
                                    :key="sub.id"
                                    @click="menuHandle(sub,false)">
                                <i :class="iconfont" :class="sub.icon"></i>
                                <span slot="title">{{sub.name}}</span>
                            </el-menu-item>
                        </el-submenu>
                        <el-menu-item v-else :index="item.id" @click="menuHandle(item,false)">
                            <i class="iconfont" :class="item.icon"></i>
                            <span slot="title">{{item.name}}</span>
                        </el-menu-item>
                    </div>
                </el-menu>
            </el-scrollbar>
        </div>
        <div class="main-container">
            <!-- <navbar /> -->
            <div class="navbar">
                <div class="head-lable">
              <span v-if="goBackFlag" class="goBack" @click="goBack()"
              ><img src="images/icons/btn_back@2x.png" alt=""/> 返回</span
              >
                    <span>{{headTitle}}</span>
                </div>
                <div class="right-menu">
                    <div class="avatar-wrapper">{{ userInfo.name }}</div>

                    <el-button type="primary" icon="el-icon-s-custom" alt="退出" @click="logout" circle></el-button>
                    <el-button icon="el-icon-switch-button" alt="退出" @click="logout" circle></el-button>
                </div>
            </div>
            <div class="app-main" v-loading="loading">
                <div class="divTmp" v-show="loading"></div>
                <iframe
                        id="cIframe"
                        class="c_iframe"
                        name="cIframe"
                        :src="iframeUrl"
                        width="100%"
                        height="auto"
                        frameborder="0"
                        v-show="!loading"
                ></iframe>
            </div>
        </div>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="element-ui/lib/index.js"></script>
<!-- 引入axios -->
<script src="plugins/axios/axios.min.js"></script>
<script src="js/request.js"></script>
<script src="./api/login.js"></script>
<script>

    new Vue({
        el: '#app',
        data() {
            return {
                defAct: '1',
                menuActived: '1',
                userInfo: {},
                menuList: [
                    {
                        id: '1',
                        name: '药品管理',
                        url: 'page/drug/list.html',
                        icon: 'el-icon-first-aid-kit'
                    },
                    {
                        id: '2',
                        name: '药品类型',
                        url: 'page/category/list.html',
                        icon: 'el-icon-tickets'
                    },
                    {
                        id: '3',
                        name: '产商管理',
                        url: 'page/manufacturer/list.html',
                        icon: 'el-icon-truck'
                    },
                    {
                        id: '4',
                        name: '员工管理',
                        url: 'page/employee/list.html',
                        icon: 'el-icon-user-solid'
                    },
                    {
                        id: '5',
                        name: '进货单明细',
                        url: 'page/purchase/list.html',
                        icon: 'el-icon-s-claim'
                    },
                    {
                        id: '6',
                        name: '库存管理',
                        url: 'page/warehouse/list.html',
                        icon: 'el-icon-s-home'
                    },
                    {
                        id: '7',
                        name: '药品进货',
                        url: 'page/purchaseDetail/list.html',
                        icon: 'el-icon-s-goods'
                    }
                ],
                iframeUrl: 'page/drug/list.html',
                headTitle: '药品管理',
                goBackFlag: false,
                loading: true,
                timer: null
            }
        },
        computed: {},
        created() {
            const userInfo = window.localStorage.getItem('userInfo')
            if (userInfo) {
                this.userInfo = JSON.parse(userInfo)
            }
            this.closeLoading()
        },
        beforeDestroy() {
            this.timer = null
            clearTimeout(this.timer)
        },
        mounted() {
            window.menuHandle = this.menuHandle
        },
        methods: {
            logout() {
                this.$confirm('是否退出登录?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    logoutApi().then((res) => {
                        if (res.code === 1) {
                            localStorage.removeItem('userInfo')
                            window.location.href = '/backend/page/login/login.html'
                        }
                    })
                    this.$message({
                        type: 'success',
                        message: '退出成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });

            },
            goBack() {
                const menu = this.menuList.find(item => item.id === this.menuActived)
                this.menuHandle(menu, false)
            },
            menuHandle(item, goBackFlag) {
                this.loading = true
                this.menuActived = item.id
                this.iframeUrl = item.url
                this.headTitle = item.name
                this.goBackFlag = goBackFlag
                this.closeLoading()
            },
            closeLoading() {
                this.timer = null
                this.timer = setTimeout(() => {
                    this.loading = false
                }, 1000)
            }
        }
    })
</script>
</body>
</html>
